package gherkinedit.editors;

import gherkinedit.utils.FilesystemUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class GherkinSentenceCrawler {

	public List<String> getGherkinSentences() {
		File currentProjectDirectory = FilesystemUtils.getCurrentProjectRootDirectory();
		List<File> files = FilesystemUtils.getFilesByExtension(currentProjectDirectory, "java");
		List<String> gherkinSentences = FilesystemUtils.getGherkinSentences(files);
		
		stripAnnotation(gherkinSentences);
		
		if (gherkinSentences.size() == 0) {
			List<String> list = new ArrayList<String>();
			list.add("No suggestions found");
			return list;
		} else {
			return gherkinSentences;
		}
	}
	
	private List<String> stripAnnotation(List<String> gherkinSentences) {
		for (int i = 0; i < gherkinSentences.size(); i++) {
			String sentence = gherkinSentences.get(i);
			sentence = sentence.substring(2, sentence.length()-3);
			System.out.println("\\(\"\\^");
			sentence = sentence.replaceFirst("\\(\"\\^", " ");
			gherkinSentences.set(i, sentence);
		}
		return gherkinSentences;
	}
}
